function addopt(id,value,text){     
    var element_id=document.getElementById(id);
    var len=element_id.options.length;
    for(var i=0;i<len;i++){
        if(element_id[i].value==value){
           return;
        }                                                        
    }
    var opt=document.createElement("option");
    opt.value=value;
    opt.text=text;
    element_id.options.add(opt);
}
function hideUnhide (stateInfo, shapeShifterId, invert) {
	elem = document.getElementById(shapeShifterId);
	if (stateInfo.options) {
		checkedOrSelected = stateInfo.selectedIndex>0;
		if (shapeShifterId == 'abn-update-block') {
			parts = stateInfo.options[stateInfo.selectedIndex].value.split(':');
			abn = parts[1];
			checkedOrSelected = checkedOrSelected && abn=='';
		}
	} else {
		checkedOrSelected = stateInfo.checked;
	}
	if (invert?!checkedOrSelected:checkedOrSelected) {
		elem.style.display = 'block';
	} else {
		elem.style.display = 'none';
		containedFields = elem.getElementsByTagName('input');
		for (i=0; i<containedFields.length; i++) {
			if (containedFields[i].type == 'text' || containedFields[i].type == 'textarea')
				containedFields[i].value = '';  
			else if (containedFields[i].type == 'select-one')
				containedFields[i].selectedIndex = 0;
			else if (containedFields[i].type == 'checkbox')
				containedFields[i].checked = false;
		}
		containedFields = elem.getElementsByTagName('select');
		for (i=0; i<containedFields.length; i++) {
			containedFields[i].selectedIndex = 0;
		}
		subHide = document.getElementById('location-fields');
		if (subHide) subHide.style.display = 'None';
	}
}

Validation.addAllThese([
		['validate-all-or-none', 'Required if this field group is used.', function(v) {
			var groupUsed;
			all = document.getElementsByClassName('validate-all-or-none');
			optional = document.getElementsByClassName('validate-optional-or-none');
			for (i=0; i<all.length; i++) {
				groupUsed = groupUsed || !Validation.get('IsEmpty').test(all[i].value);
			}
			for (i=0; i<optional.length; i++) {
								groupUsed = groupUsed || !Validation.get('IsEmpty').test(optional[i].value);
						}
			if (groupUsed) {
				return !Validation.get('IsEmpty').test(v);
			} else {
				return true;
			}
				}],
	['validate-one-if-none', 'You must select or enter details.', function(v,elm) {
			var groupUsed;
			all = document.getElementsByClassName('validate-all-or-none');
			optional = document.getElementsByClassName('validate-optional-or-none');
			for (i=0; i<all.length; i++) {
				groupUsed = groupUsed || !Validation.get('IsEmpty').test(all[i].value);
			}
			for (i=0; i<optional.length; i++) {
				groupUsed = groupUsed || !Validation.get('IsEmpty').test(optional[i].value);
			}
			if (groupUsed) {
				return true;
			} else {
				var options = document.getElementsByClassName('validate-one-if-none');
				return $A(options).any(function(elm) {
					return $F(elm);
				});
			}
		}],
	['validate-phone', 'Format: +1[11] 2[2222] 333[3] 444[4]', function(v) {
			return Validation.get('IsEmpty').test(v) || /^\+\d\d?\d? \d\d?\d?\d?\d? \d\d\d\d? \d\d\d\d?$/.test(v)
		}]
]);
function search(fromobj,toobj){
        var sel = document.getElementById(toobj);         
        var sour = document.getElementById(fromobj);
        var txt=sour.value.toLowerCase();
        if(txt == undefined || txt == ''){
                return;
        }        
        for(var i = sel.length - 1; i >= 0; i--){                
                if(sel.options[i].text.toLowerCase().indexOf(txt)<0)
                {
                        sel.remove(i);
                }
        }
        if(sel.options.length > 0){
                sel.options[0].selected = true;
        }
        else{                
                alert("No matched");
                sour.value='';                
                window.location.reload();
        }
}
//check all the checkbox
flag=1;
function selectAll(obj){                
        chk_ids=document.getElementsByName(obj);                   
        len=chk_ids.length;
        if(flag==1){
                for (i=0;i<len;i++){
                       chk_ids[i].checked=true;
                }              
                flag=0;
        }else{
                for (i=0;i<len;i++){
                       chk_ids[i].checked=false;
                }  
                flag=1;
        }
}
//check checkbox checked or not
function check_chk(obj){                    
        var flag=false;
        var chk_ids=document.getElementsByName(obj);         
        var len = chk_ids.length;
        for (i=0;i<len;i++){
                if(chk_ids[i].checked==true){
                        flag=true;
                        break;
                }
        }                
        if(flag==true){ 
                if(confirm("Are you sure to change those?")){
                        return true;
                }else{
                        return false;
                }
        }else{
                alert('NO one checked,Please check one!');
                return false;
        }
}
function getElementsByName_ie(tag, name){
		var elem = document.getElementsByTagName(tag);
		var arr = new Array();
		for(i = 0,iarr = 0; i < elem.length; i++){
				att = elem[i].getAttribute("name");
				if(att == name){
						arr[iarr] = elem[i];
						iarr++;
				}
		}
		return arr;
}
